<template>
  <div class="diversions">
    <el-form ref="form" :model="form" size="mini" style="display:flex;">
      <el-form-item label="广播内容" style="display:flex;margin:0 50px 0 0">
        <el-input v-model="form.name" type="textarea" :rows="1" style="width:600px" placeholder="请输入广播内容">
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="savebutton">保存</el-button>
      </el-form-item>
    </el-form>
    <!-- 表格 -->
    <el-table style="margin:20px 0 0 0" size="mini" :header-cell-style="{
        color: '#fff',
        background: '#6090EC',
        fontSize: '11px',
        fontWeight: 'normal',
      }" :data="airportLists" border stripe>
      <el-table-column label="广播内容" prop="name"></el-table-column>
      <el-table-column label="创建人" prop="employeeName" width="100ppx"></el-table-column>
      <el-table-column label="创建时间" prop="createDate" width="140ppx"></el-table-column>
      <el-table-column label="是否显示" prop="isshow" width="100ppx">
        <template slot-scope="scope">
          <template v-if="scope.row.isshow=='true'">是</template>
          <template v-if="scope.row.isshow=='false'">否</template>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="160px">
        <template slot-scope="scope">
          <el-popconfirm title="确定删除该广播吗？" @confirm="confirmDeletion">
            <el-button slot="reference" type="primary" size="mini" @click="dealwith(scope.row)">删除</el-button>
          </el-popconfirm>
          <el-button v-if="scope.row.isshow=='false'" style="margin:0 0 0 20px;" type="primary" size="mini" @click="useButton(scope.row)">启用</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
      :page-sizes="[10, 15, 20]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
      :total="pageTotal">
    </el-pagination>
  </div>
</template>

<script>
  export default {
    name: 'diversions',
    data() {
      return {
        id: "",
        pageTotal: 0,
        pageSize: 1,
        currentPage: 10,
        airportLists: [],
        form: {
          name: "",
        },
      }
    },
    methods: {
      // 列表
      getmarquee() {
        this.$axios.getmarquee().then((res) => {
          console.log(res)
          this.airportLists = res.data
          this.pageTotal = res.total
        })
      },
      // 使用按钮
      useButton(row) {
        console.log(row)
        this.$axios.postenable({
          id: row.id
        }).then((res) => {
          console.log(res)
          if (res.code == 200) {
            this.$message({
              message: '启用成功',
              type: 'success'
            });
            this.form.name=''
            this.getmarquee()
            this.$router.go(0)
          }
        })
      },
      // 保存
      savebutton() {
        if (this.form.name == '') {
          this.$message({
            message: '请输入广播内容后再保存',
            type: 'warning'
          });
        } else {
          localStorage.setItem("isToken", true);
          this.$axios.getaddMarquee(this.form).then((res) => {
            
            console.log(res)
            if (res.code == 200) {
              this.$message({
                message: '新增成功',
                type: 'success'
              });
              this.getmarquee()
              this.$router.go(0)
            }
          })
        }
      },
      // 删除按钮
      dealwith(row) {
        console.log(row)
        this.id = row.id
      },
      // 确认删除按钮
      confirmDeletion() {
        this.$axios.postremove({
          id: this.id
        }).then((res) => {
          console.log(res)
          if (res.code == 200) {
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            this.getmarquee()
          }
        })

      },
      //分页
      handleSizeChange(value) {
        console.log("1", value);
        localStorage.setItem("pageSize", value);
        localStorage.setItem("pageNum", 1);
        this.getmarquee();
        this.pageSize = value;
      },
      handleCurrentChange(value) {
        console.log("2", value);
        localStorage.setItem("pageNum", value);
        localStorage.setItem("pageSize", this.pageSize);
        this.getmarquee();
        // orders = res.data;
      },
    },
    mounted() {
      this.getmarquee()
    },
  }
</script>

<style scoped>
  .diversions {
    margin: 20px;
  }
</style>